﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Employee_HRViewIntervewInformation : System.Web.UI.Page
{
    string VacancyID;
    int PageSize = 20;
    string UserName = "";
    EmployeeMethord EM = new EmployeeMethord();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            UserName = Session["User"].ToString();
            VacancyID = Request.QueryString["ID"].ToString();
            DataSet ds = EM.ReturnDataSearch(VacancyID, "VacancyID", UserName);
            LoadData(ds);
        }
        catch (Exception ex)
        {
            if (!Page.IsPostBack)
            {
                DataSet ds = EM.ReturnAllInterviewInfor(UserName);
                LoadData(ds);
            }
        }
    }
    private void LoadData(DataSet ds)
    {
        try
        {
            Session["InterviewInfor"] = ds;
            GVInterviewInfor.DataSource = ds.Tables[0].DefaultView;
            GVInterviewInfor.DataBind();
            ShowData(ds.Tables[0], 0);
        }
        catch (Exception ex)
        {
        }
    }
    private void ShowData(DataTable tb, int _PageIndex)
    {
        try
        {
            int CurentLastIndex = 0;
            int PageIndex = _PageIndex;
            if (tb.Rows.Count >= PageSize * (PageIndex + 1))
            {
                CurentLastIndex = (PageIndex + 1) * PageSize;
            }
            else
            {
                CurentLastIndex = tb.Rows.Count;
            }
            for (int row = PageIndex * PageSize; row < CurentLastIndex; row++)
            {
                for (int column = 0; column < GVInterviewInfor.Columns.Count; column++)
                {
                    string Value = "";
                    switch (column)
                    {
                        case 1:
                            Value = "<a href=\"HRViewInterviewerInfor.aspx?ID=" + tb.Rows[row][column].ToString() + "\">";
                            Value += EM.ReturnNameFollowID(tb.Rows[row][column].ToString(), "Intervewer");
                            Value += "</a>";
                            break;
                        case 2:
                            Value = "<a href=\"HRViewVacancyDetails.aspx?ID=" + tb.Rows[row][column].ToString() + "\">";
                            Value += tb.Rows[row][column].ToString();
                            Value += "</a>";
                            break;
                        case 3:
                            Value = "<a href=\"HRApplicantInformation.aspx?ID=" + tb.Rows[row][column].ToString() + "\">";
                            Value += EM.ReturnNameFollowID(tb.Rows[row][column].ToString(), "Applicant");
                            Value += "</a>";
                            break;
                        case 4:
                            Value = "<a href=\"HRChangeInterview.aspx?ID=" + tb.Rows[row][0].ToString() + "\">";
                            Value += tb.Rows[row][column].ToString().Substring(0, tb.Rows[row][column].ToString().IndexOf(" "));
                            Value += "</a>";
                            break;
                        case 6:
                            switch (tb.Rows[row][column].ToString())
                            {
                                case "1":
                                    Value = "<a href=\"HRChangeInterview.aspx?ID=" + tb.Rows[row][0].ToString() + "\">Accept</a>";
                                    break;
                                case "2":
                                    Value = "<a href=\"HRChangeInterview.aspx?ID=" + tb.Rows[row][0].ToString() + "\">Waiting</a>";
                                    break;
                                case "3":
                                    Value = "<a href=\"HRChangeInterview.aspx?ID=" + tb.Rows[row][0].ToString() + "\">No Accept</a>";
                                    break;
                            }
                            break;
                        default:
                            Value = "<a href=\"HRChangeInterview.aspx?ID=" + tb.Rows[row][0].ToString() + "\">";
                            Value += tb.Rows[row][column].ToString();
                            Value += "</a>";
                            break;
                    }
                    GVInterviewInfor.Rows[row - (PageIndex * PageSize)].Cells[column].Text = Value;
                }
            }
        }
        catch (Exception ex)
        {
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        DataSet ds = null;
        if (ddlTypeSearch.SelectedValue == "Date Interview")
        {
            ds = EM.ReturnDataSearch(txtDateSearch.Text, ddlTypeSearch.SelectedValue, UserName);
        }
        else if (ddlTypeSearch.SelectedValue == "Status")
        {
            ds = EM.ReturnDataSearch(ddlStatus.SelectedValue, ddlTypeSearch.SelectedValue, UserName);
        }
        else
        {
            ds = EM.ReturnDataSearch(txtTextSearch.Text, ddlTypeSearch.SelectedValue, UserName);
        }
        LoadData(ds);
    }
    protected void GVInterviewInfor_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            DataSet dsCurrent = (DataSet)Session["InterviewInfor"];
            GVInterviewInfor.DataSource = dsCurrent.Tables[0].DefaultView;
            GVInterviewInfor.PageIndex = e.NewPageIndex;
            GVInterviewInfor.DataBind();
            ShowData(dsCurrent.Tables[0], GVInterviewInfor.PageIndex);
        }
        catch (Exception ex)
        {
        }
    }
}